<?php 
$cityId=getParameter($portletUID."city");
?>
<div id="login">






	<fieldset class="account_creation">
<form class="std border" id="account-creation_form" method="post" action="<?php echo createUrl("pageName",getParameter("pageName")); ?>">

    <h1><?php echo $var_shop_newaccount; ?></h1>

    <div style="float:left">
            <h2><?php echo $var_shop_personal_infos; ?></h2>
	
		<p class="civ required">
			<span><?php echo $var_shop_civ; ?></span>
			<input type="radio" value="MR" id="id_gender1" name="civ" checked="checked">
			<span class="top" for="id_gender1"><?php echo $var_shop_civ_1; ?></span>
			<input type="radio" value="MM" id="id_gender2" name="civ">
			<span class="top" for="id_gender2"><?php echo $var_shop_civ_2; ?></span>
			<input type="radio" value="ML" id="id_gender3" name="civ">
			<span class="top" for="id_gender3"><?php echo $var_shop_civ_3; ?></span>
		</p>
		<p class="required text">
			<label for="customer_firstname"><?php echo $var_shop_firstname; ?></label>
			<?php formText($portletUID."customer_firstname",0,"account_input"); ?>
			<sup>*</sup>
		</p>
		<p class="required text">
			<label for="customer_lastname"><?php echo $var_shop_lastname; ?></label>
			<?php formText($portletUID."customer_lastname",0,"account_input"); ?>
			<sup>*</sup>
		</p>
		<p class="required text">
			<label for="email"><?php echo $var_shop_mail; ?></label>
			<?php
			if (getParameter("mail"))  $_REQUEST[$portletUID."email"]=getParameter("mail") ; 
			 
			 
			 ?>
			<?php formText($portletUID."email",0,"account_input"); ?>
			<sup>*</sup>
		</p>
		<p class="required password">
			<label for="passwd"><?php echo $var_shop_password; ?></label>
			<?php formPassword($portletUID."passwd",0,"account_input"); ?>
			<sup>*</sup>
			<span class="form_info"><?php echo $var_shop_password_min; ?></span>
		</p>
    <p class="required password">
        <label for="passwd"><?php echo $var_shop_confirmation; ?></label>
        <?php formPassword($portletUID."confpasswd",0,"account_input"); ?>
        <sup>*</sup>

    </p>
		<p class="select">
			<label ><?php echo $var_shop_birthday; ?></label>
			<?php formDate($portletUID."birthday","account_input"); ?>
			
		</p>
		
		<h2><?php echo $var_shop_company; ?></h2>
		
		<p class="text">
			<label for="company"><?php echo $var_shop_company_name; ?></label>
			<?php formText($portletUID."company",0,"account_input"); ?>
		</p>
			<p class="text">
				<label for="patente"><?php echo $var_shop_businesstax; ?></label>
				<?php formText($portletUID."patente",0,"account_input"); ?></span>
				
			</p>
    </div>
    <div style="float:right;width: 473px;">
		
		<h2><?php echo $var_shop_contact_infos; ?></h2>

		<p class="required text">
			<label for="adress1"><?php echo $var_shop_streetadress; ?></label>
			<?php formText($portletUID."adress1",0,"account_input"); ?>
			<sup>*</sup>
		</p>
		<p class="text">
			<label for="adress2"><?php echo $var_shop_streetadress2; ?></label>
			<?php formText($portletUID."adress2",0,"account_input"); ?>
		</p>
		<p class="required postcode text">
			<label for="postcode"><?php echo $var_shop_zipcode; ?></label>
			<?php formText($portletUID."postcode",0,"account_input"); ?>
			<sup>*</sup>
		</p>
		<p class="required text">
			<label for="city"><?php echo $var_shop_city; ?></label>
			
<!--
<select  title="" name="<?php echo $portletUID; ?>city" id="<?php echo $portletUID; ?>city" >
<option value="none"><?php echo $var_portal_choose; ?></option>
<?php

$sSql ="SELECT portal_cities.lib_".$lt." as lib,portal_cities.id  FROM portal_countries INNER JOIN portal_cities ON portal_countries.id = portal_cities.countryId WHERE portal_countries.lib_lt = 'Maroc' ORDER BY portal_cities.lib_lt ASC ";
      $rs=$GLOBALS["conn"]->Execute($sSql); 
		
 while ( !$rs->EOF)  { 
 	
		  ?>
<option  <?php if ($cityId==$rs->fields["id"]) echo "Selected"; ?> value="<?php echo $rs->fields["id"]; ?>"><?php echo $rs->fields["lib"]; ?></option>

				  <?php
		  $rs->MoveNext();

		  }


	
?>
</select>-->

            <?php formText($portletUID."city",0,"account_input"); ?>
			<sup>*</sup> <?php formError($portletUID."city"); ?>
		</p>
		
		
			<p class="text">
			<label for="phone"><?php echo $var_shop_landline; ?></label>
			<?php formText($portletUID."phone",0,"account_input"); ?>
		</p>
		<p class="text">
			<label for="phone_mobile"><?php echo $var_shop_mobile; ?></label>
			<?php formText($portletUID."phone_mobile",0,"account_input"); ?>
		</p>
		
		<p class="textarea">
			<label for="other"><?php echo $var_shop_moreinfos; ?></label>
			</textarea><?php formTextArea($portletUID."other",26,3,"account_input"); ?>
		</p>

    </div>

	<p class="createaccount_submit required submit">
			<input type="submit" class="button"  value="<?php echo $var_shop_newaccount_submit; ?>" id="createAccount" name="<?php echo $portletUID?>createAccount">
			<br clear="all" />
			<br clear="all" />
		
	</p>

<span><sup>*</sup><?php echo $var_shop_required; ?></span>
</form>

	</fieldset>

						
						<?php

						if (getParameter($portletUID."createAccount"))
						
						{
							$error=false;
						
						if (getParameter($portletUID."email")==null || ew_CheckEmail(getParameter($portletUID."email"))==FALSE) displayError($var_shop_mailrequired,$portletUID."email");
						if (getParameter($portletUID."customer_firstname")==null) displayError($var_shop_firstnamerequired, $portletUID."customer_firstname");
						if (getParameter($portletUID."customer_lastname")==null) displayError($var_shop_lastnamerequired, $portletUID."customer_lastname");
						//if (getParameter($portletUID."birthday")==null) displayError("Veuillez saisir un prénom.", $portletUID."birthday");
						if (getParameter($portletUID."passwd")==null || CheckPassword(getParameter($portletUID."passwd"))<3) displayError($var_shop_invalidpassword.getPasswordScore(CheckPassword(getParameter($portletUID."passwd")))."",$portletUID."passwd");
                        if (getParameter($portletUID."passwd")!=getParameter($portletUID."confpasswd"))  displayError($var_shop_confirmpassword, $portletUID."confpasswd");


						if ($app_shop_isB2B=="yes" && getParameter($portletUID."company")==null) displayError($var_shop_companyrequired, $portletUID."company");
						
						
						if ($app_shop_isB2B=="yes" && getParameter($portletUID."patente")==null) displayError($var_shop_businesstaxrequired, $portletUID."patente");
						
						if (getParameter($portletUID."adress1")==null) displayError($var_shop_adressrequired, $portletUID."adress1");
						
						if (getParameter($portletUID."postcode")==null) displayError($var_shop_zipcoderequired, $portletUID."postcode");
						
						
						
						if ($cityId=="none") displayError($var_shop_cityrequired, $portletUID."city");
						
						if (checkDuplicates("portal_logins","portalId",$portalId,"mail",getParameter($portletUID."email"))) displayError($var_shop_duplicatemail, $portletUID."email");
						if ($app_shop_isB2B=="yes" && checkDuplicates("shop_clients","portalId",$portalId,"patente",getParameter($portletUID."patente"))) displayError($var_shop_duplicatebusinesstax, $portletUID."patente");
						if ($app_shop_isB2B=="yes" && checkDuplicates("shop_clients","portalId",$portalId,"company",getParameter($portletUID."company"))) displayError($var_shop_duplicatecompany, $portletUID."company");
						if (checkDuplicates("shop_clients","portalId",$portalId,"firstname",getParameter($portletUID."customer_firstname"),"lastname",getParameter($portletUID."customer_lastname"))) displayError($var_shop_duplicateperson, $portletUID."customer_lastname");
						if ($error==false)
						{
							
							$mail=getParameter($portletUID."email");
							
							$loginId=null;
							$promo=1;
							$loginId=addPortalUser($mail,getParameter($portletUID."passwd"),$mail,$portalId,4);
							
							$parrain=getClientIdByMail(TEAdecrypt(getParameter("sponsor"),KEY));
							if (!$parrain) {
								$parrain='NULL';
								$promo=0;
							}

							
							$sSql="INSERT INTO `shop_clients` (portalId,loginId,company,patente,phone,mobile,civ,firstname,lastname,birthday,adress,adress2,postalcode,city,country,moreinfo,adddate,parrain,promo)
							 VALUES (".$portalId.",".$loginId.",'".getParameter($portletUID."company")."','".getParameter($portletUID."patente")."','".getParameter($portletUID."phone")."','".getParameter($portletUID."phone_mobile")."','".getParameter($portletUID."civ")."','".getParameter($portletUID."customer_firstname")."','".getParameter($portletUID."customer_lastname")."','".getParameter($portletUID."birthday")."','".getParameter($portletUID."adress1")."','".getParameter($portletUID."adress2")."','".getParameter($portletUID."postcode")."','".$cityId."','".getCountryId("Maroc")."','".getParameter($portletUID."other")."','".ew_CurrentDateTime()."',".$parrain.",".$promo.");";
				//echo $sSql;
				// check if the client is inserted , if not delete portaluser and throw and error


	
				$GLOBALS["conn"]->Execute($sSql);

                            if (getObjByKey("shop_clients","loginId","portalId",$portalId,"loginId",$loginId)==null)
                            {

                              //  echo $mail;
                            removePortalUser($portalId,$mail);
                                ShowError($var_shop_generalerror);
                            }else{

				$key=TEAencrypt($mail,KEY);
				$host=$_SERVER['HTTP_HOST'];
				if (isLocal())  $host=getPortalUrl().".betasite.net";
				$link="http://".$host."/?pageName=client_area&key=".$key;


                                $data=array();
                                $data["link"]=$link;
                                $data["portal"]=getPortalName();
                                $data["customer"]=getParameter($portletUID."customer_firstname");
                                sendMailTo($mail, TemplateWithData($var_shop_mail_accountsaved,$data));
				


                                $data=array();
                                $data["company"]=getParameter($portletUID."company");
                                $data["customer_firstname"]=getParameter($portletUID."customer_firstname");
                                $data["customer_lastname"]=getParameter($portletUID."customer_lastname");

                                sendMailToAdmins($portalId, TemplateWithData($var_shop_accountsavedadmin,$data));

				header("Location: ".createUrl("pageName","login","action","login","login",getParameter($portletUID."email"),"password",TEAencrypt(getParameter($portletUID."passwd"),KEY)));
                            }
                        }
						}
						?>
						</div>
						
<style>
						
	.formerror {
    color: red;
    display: block;
    position: absolute; 
    margin-left: 143px;
    margin-top: -1px;
}

</style>